#compdef cargo
+
typeset -A opt_args
autoload -U regexp-replace
echo $manifest
}
-#gets test names from the manifest file
-_test_names(){
-local -a filelist;
-local manifest=$(_locate_manifest)
-if ! [[ $manifest ]]; then
- return 0
-fi
-
-local last_line
-local -a tests;
-tests=()
-while read line
-do
- if [[ $last_line == '[[test]]' ]]; then
- regexp-replace line '^.*name *= *|"' ""
- tests+=$line
+# Extracts the values of "name" from the array given in $1 and shows them as
+# command line options for completion
+_get_names_from_array()
+{
+ local -a filelist;
+ local manifest=$(_locate_manifest)
+ if ! [[ $manifest ]]; then
+ return 0
fi
- last_line=$line
-done < $manifest
-_describe 'tests' tests
+
+ local last_line
+ local -a names;
+ local in_block=false
+ local block_name=$1
+ names=()
+ while read line
+ do
+ if [[ $last_line == "[[$block_name]]" ]]; then
+ in_block=true
+ else
+ if [[ $last_line =~ '.*\[\[.*' ]]; then
+ in_block=false
+ fi
+ fi
+
+ if [[ $in_block == true ]]; then
+ if [[ $line =~ '.*name.*=' ]]; then
+ regexp-replace line '^.*name *= *|"' ""
+ names+=$line
+ fi
+ fi
+
+ last_line=$line
+ done < $manifest
+ _describe $block_name names
+
+}
+
+#Gets the test names from the manifest file
+_test_names()
+{
+ _get_names_from_array "test"
}
_cargo